package com.serve.oa.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.serve.oa.entity.SysUser;
import com.serve.oa.jwt.JwtUtil;
import com.serve.oa.service.*;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.ServletRequestUtils;

import javax.servlet.http.HttpServletRequest;

public class BaseController {
    @Autowired
    SysUserService userService;

    @Autowired
    SysUserRoleService userRoleService;

    @Autowired
    SysRoleService roleService;


    @Autowired
    SysMenuService menuService;


    @Autowired
    SysRoleMenuService roleMenuService;

    @Autowired
    RedisTemplate redisTemplate;

    @Autowired
    HttpServletRequest req;


    public <K> Page<K> getPage() {
        int current = ServletRequestUtils.getIntParameter(req, "cuurent", 1);
        int size = ServletRequestUtils.getIntParameter(req, "size", 5);

        return new Page(current, size);
    }
    public SysUser curUser(){
        String SS = (String) SecurityUtils.getSubject().getPrincipal();
        SysUser user =  userService.getOne(new QueryWrapper<SysUser>().eq("username",JwtUtil.getUsername(SS)));
        return user;

    }

}
